const http = require('http')

const server = http.createServer()
//为服务器实例绑定request 事件 ，监听客户端
server.on('request', function (req, res) {

    const url = req.url //获取url地址

    let content = `<H1>404 Not Found</H1>`

    if (url === '/' && url === '/index.html') {
        content = `<H1>首页</H1>`

    } else if (url === '/about.html') {
        content = `<H1>关于首页</H1>`
    }
    req.setHeader('Content-type', 'text/html;charset=utf-8')

    // 内容发送到客户端
    res.end(content)


})
server.listen(8080, function () {
    console.log('xizhupeiqi http://127.0.0.1:8080');
})
